<?php
	$first_name		= $this->formText('first_name', $this->Item['first_name'], array('placeholder' => 'First name'));
	$last_name		= $this->formText('last_name', $this->Item['last_name'], array('placeholder' => 'Last name'));
	$email			= $this->formText('email', $this->Item['email'], array('placeholder' => 'Email address'));
	$password		= $this->formPassword('password', $this->Item['password'], array('placeholder' => 'Password'));

	$avatar 		= $this->formFile('avatar', array('class' => 'file'));

	$sub_title		= 'Add new user';
	if($this->arrParam['action'] == 'edit'){
		$configObj  = new Zendvn_Controller_Config(array('module'=>$this->arrParam['module'],
													 	  'fileConfig'=>'user.ini'));
		$itemConfig = $configObj->getConfig('config');
		if(!empty($this->Item['avatar']) && file_exists($itemConfig['thumbDir3'] . '/' . $this->Item['avatar'])){
			$avatarUrl = $itemConfig['thumbUrl3'] . '/' . $this->Item['avatar'];
		}
		$current_avatar = $this->formHidden('current_avatar',$this->Item['avatar']);
		$avatar .=	$current_avatar;

		$sub_title		= 'Update user information';
	}

	$birthday		= $this->formText('birthday', $this->Item['birthday'], array('class' => 'date-picker', 'data-date-format' => 'yyyy-mm-dd', 'placeholder' => 'Birthday'));

	$group_id		= $this->cmsSelect('group_id', $this->Item['group_id'], array('class' => 'chzn-select', 'style' => 'width: 238px'), $this->sblGroup);

	$options		= array('active' => 'Active', 'inactive' => 'Inactive');
	$status			= $this->formSelect('status', $this->Item['status'], array('class' => 'chzn-select', 'style' => 'width: 238px'), $options);

	$sign			= Zendvn_Filter_Filter::filterContent($this->Item['sign']);
	$sign			= $this->tinyMce('sign',$sign,array('style'=>"width: 100%; height: 250px;"));


	$arrRow = array(
					array('label'=>$this->translate('First Name'), 'input'=>$first_name),
					array('label'=>$this->translate('Last Name'), 'input'=>$last_name),
					array('label'=>$this->translate('Email'), 'input'=>$email),
					array('label'=>$this->translate('Password'), 'input'=>$password),
					array('label'=>$this->translate('Group'), 'input'=>$group_id),
					array('label'=>$this->translate('Avatar'), 'input'=>$avatar),
					array('label'=>$this->translate('Birthday'), 'input'=>$birthday),
					array('label'=>$this->translate('Status'), 'input'=>$status),
					array('label'=>$this->translate('Sign'), 'input'=>$sign)
				);

	$linkAction 	= $this->cmsUrl(array('action' => $this->arrParam['action'], 'id' => $this->arrParam['id']));
	$linkBack 		= $this->cmsUrl(array('action' => 'index'));
?>
<?php echo $this->partial($this->includeDir . '/submenu.php', array('main_title' => 'Users Manager', 'sub_title' => $sub_title));?>
<div class="row-fluid">
	<div class="alert alert-success frm_msg" style="display: none">
		<button type="button" class="close" data-dismiss="alert"><i class="icon-remove"></i></button>
		<strong><i class="icon-ok"></i> <span id="frm_msg"></span></strong>
	</div>
	<div class="span12">
		<form class="form-horizontal" id="appForm" method="post" action="<?php echo $linkAction;?>" enctype="multipart/form-data"/>
			<?php echo $this->partialLoop('row.php',$arrRow);?>
			<div class="form-actions">
				<button class="btn btn-info" type="submit">
					<i class="icon-ok bigger-110"></i>
					Submit
				</button>

				&nbsp; &nbsp; &nbsp;
				<a class="btn" href="<?php echo $linkBack?>">
					<i class="icon-undo bigger-110"></i>
					Back
				</a>
			</div>
		</form>
	</div>	
</div>

<script>
	$(function(){
		$("#avatar").fileinput({
			<?php if(!empty($avatarUrl)):?>
			initialPreview: [
		        "<img src='<?php echo $avatarUrl?>' class='file-preview-image'>",
		    ],
		    <?php endif;?>
			showUpload: false,

		});

		$('#appForm').ajaxForm({
			dataType 	: 'json', 
			beforeSubmit : function(){
				$('.global-ajax-loading').show();
			},
			success 	: function(data){
				console.log(data);
				$('.global-ajax-loading').hide();
				if(data.type == 'error'){
					loadFormError($('#appForm'), data.msg);
				}else{
					$('#frm_msg').html(data.msg).parents('.frm_msg').delay(500).fadeIn(700);
				}
				anchorAnimate($('.page-header'));
			}
		})
	})
</script>